def check(){
    def a = ""
    def b = null
    if (a?.trim()){  //  a为null或""  a?.trim()表达式为false
        println("not empty or null")
    }
    else {
        def c = a?.trim()
        println c
        println("a is empty or null")
    }    
}


def substring_groovyStyle(){
    // groovy风格的字符串截取
    def text1 = "My last character will be removed soon"    
    println text1[0..-2] // My last character will be removed soo   
    
    def text2 = "My first word will be removed soon";    
    println text2[3..-1] // first word will be removed soon   
    
    def text3 = "noos em daer lliw uoy ,tneitap eB"    
    println text3[-1..0] // Be patient, you will read me soon   

    def microserviceVersion = "KQGateway-win-uims-20220712_140137_daily_build_alpha.rar"
    println("RESULT: " + "${microserviceVersion}"[19..-5]) 
    println("RESULT: " + "${microserviceVersion[19..-5]}") 
    println("RESULT: " + microserviceVersion[19..-5]) 
}
substring_groovyStyle()

def substring(){
    // substring
    def log = "Exception on saving user with username:johntheripper"  
    def username = log.substring(log.lastIndexOf(":") + 1, log.length())        
    println username // johntheripper   

    // subSequence
     log = "Exception on saving user with username:johntheripper"    
     username = log.subSequence(log.lastIndexOf(":") + 1, log.length())    
    println username // johntheripper


    result ="KQGIS_Desktop_Win64_V8.5_release.rar"
    println(result.substring(0,result.length()-4))
    println("${result.substring(0,result.length()-4)}")

    desktopZipName = "KQGIS_Desktop_Win64_V8.5_20220614_135403_daily_build_alpha.rar"
    println("RESULT: ${desktopZipName.substring(0, desktopZipName.length() - 4).substring(14)}")
}

def join(){
    // 参见: basic_collection.groovy

    println("JOIN RESULT: " + [1,2].join(";"))
}
join()

def replace(){
    println "1,2,3".replace(",","/")

    println "1.2".replace(".", "/")
}


def trim(){
    println "  12 3 ".trim()
}


def contains(){
    println "1.1.1-20201102100215-alpha | war".contains("war")

}

def placeholder(){
    def x=1
    def y = 2
    println "${x}-${y}"

    // ====== 插值 , 只有 "" 可以, ''不行
    def a1 = "L"
    def a2 = "Q"
    println "${a1}${a2}"
    println '${a1}${a2}'
    println a1
}

def split(){
    def ss = "front_sdjc"
    println "${ss.split('_')[0]}"

    println "1.1.1-20201102100215-alpha | war".split("\\|")
    
    // 默认按空格
    println "1   2    3".split()

    println  "12,3".split(",")[0]

    aa = 	"/服务管理/服务目录/注册服务z"
    println "${aa.split('/')[3]}"
    println aa.split('/').size()
}


def 三元表达式(){
    ss = "成功1"
    println """${ss.contains('成功')? "<font>${ss}-成功</font>": "<font>${ss}-失败</font>"}"""
}

def check_if_empty(){
      def str = null
     
      if (str){
         println "str is not null"
      } else {
         println 'str is null'
      }

      str = ''
     
      if (str){
         println "str is not null"
      }else{
         println 'str is null'
      }

      if(!str){
           println "'' is null"
      }else{
          println "'' is not null"
      }
}



def replace_(){
    def aaa = "com.kanq.zrzy"
    println "${aaa.replace('.', '/')}"    

    // 多重替换
    def sss = "xxx.zip"
    def st = "20210101"
    println """${sss.replace('.', "${st}.")}"""
}


def endsWith(){
    println "123".endsWith("3")
}

def encode(){
    println java.net.URLEncoder.encode("服务目录管理", "UTF-8")
}

def encode2(){
    println(new String("夫礼者".getBytes("UTF-8"), "UTF-8"));
    println(new String("夫礼者"));

    println(new ByteArrayInputStream("夫礼者".getBytes()))
    //println(IOGroovyMethods.getText(new ByteArrayInputStream("夫礼者".getBytes()), "utf-8"));
}
encode2()


def decode(){
    println java.net.URLDecoder.decode("%2F%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%2F%E6%9C%8D%E5%8A%A1%E7%9B%AE%E5%BD%95%2F001-%E6%B3%A8%E5%86%8C%E6%9C%8D%E5%8A%A1%2C%2F%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%2F%E6%9C%8D%E5%8A%A1%E7%9B%AE%E5%BD%95%2F002-%E6%95%B0%E6%8D%AE%E6%9C%8D%E5%8A%A1%2C%2F%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%2F%E6%9C%8D%E5%8A%A1%E7%9B%AE%E5%BD%95%2F003-%E4%B8%89%E7%BB%B4%E6%9C%8D%E5%8A%A1%2C%2F%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%2F%E6%9C%8D%E5%8A%A1%E7%9B%AE%E5%BD%95%2F004-%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86")
}

def other(){
    // 直接再 ${}重操作
    def a ="/1/1/2/3/"
    println "${a.replace('/', '\\')}"
    // 三元表达式
    println "${a.contains('1') ? a : '999999'}" 


}

//decode()

// println "123" == "123"
// println "123" == "1423"


// println "1"+"2"

// println '''123---LQ'''


// for (i in [1..4]){
//     println i
// }

// def ss = "123"
// def aa = "${ss}-123"
// println aa
//check_if_empty()

println(0.0 == "0.0")
println("0.0" == "0.0")

RECEIVERS="1,2,3"
println("${RECEIVERS}".split(",").getClass())
println("${RECEIVERS}".split(","))


println "" ? "TRUE":"FALSE"


result = "1,2,3"
println "${result.replace('3','2')}"

result ="aaaaaBBB.txt"
println("${result.split('\\.')[0]}")
println(result.split("\\."))

println(result.substring(5))


// 字符串为空
$empty = null
// 没有下面这行报错： Cannot invoke method isEmpty() on null object
$empty = $empty?: ""
if($empty.isEmpty()){
    println "str is empty"
}else{
    println "str is not empty"
}


